<section class="content-header" >
    <h1>
        信息管理
        <small>信息列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="{:U('/Admin/index')}"><i class="fa fa-home"></i>首页</a></li>
        <li class="active">信息管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="box-title"><label >信息列表</label></div>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <table id="table" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>车辆</th>
                                <th>反馈信息</th>
                                <th>提交时间</th>
                                <th>图片</th>
                                <th>处理</th>
                                <th>类型</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
    var feedbackTable;
    $(function () {
        feedbackTable = $('#table').dataTable({
            "autoWidth": true,
//            "order": [4,'desc'],
            "processing": true, //载入数据的时候是否显示“载入中”
            'ordering': false, //排序操作在服务端进行，所以可以关了。
            'serverSide': true,
            "searching": false,
            "ajax": {
                "url": "{:U('Feedback/index')}",
                "type": "POST"
            },
            "columns": [
                {"data": "id"},
                {"data": "car"},
                {"data": "content"},
                {"data": "addtime"},
                {"data": "imgs"},
                {"data": "result"},
                {"data": "type"},
                {"data": "id"}
            ],
            "columnDefs": [
                {
                    "targets": 4,
                    "render": function (data, type, row) {
                        var html = "";
                        if(data!=""){
                            var imgs = data.split("|");
                            for(var i=0;i<imgs.length;i++){
                                html+='<img src="'+imgs[i]+'" width="40" onclick="showImg(\''+ imgs[i] + '\')">';
                            }
                        }
                        return html;


                    }
                },
                {
                    "targets": 5,
                    "render": function (data, type, row) {
                        if(row.type==1){
                            return data==0?'待处理':"<span style='color: red;'>已共享</span>";
                        }else{
                            return data==0?'待处理':(data==1?"<span style='color: red;'>已处理</span>":"<span style='color: red;'>已拒绝</span>");
                        }
                    }
                },
                {
                    "targets": 6,
                    "render": function (data, type, row) {
                        var types = [0,"路况反馈","事故报告","检修申请"];
                        return types[data];
                    }
                },
                {
                    "targets": 7,
                    "render": function (data, type, row) {
                        var html  ="";
                        if(row.type==1){
                            if(row.result==0){
                                html += '<a href="javascript:shareItem(' +data + ')"><i class="fa fa-edit"></i>&nbsp;发布共享</a><br/>';
                            }
                        }else if(row.type==2){
                            html+='<a href="javascript:uptateItem(' + data + ',1)"><i class="fa fa-edit"></i>&nbsp;已查看</a><br/>' ;
                        }else{
                            html+='<a href="javascript:uptateItem(' + data + ',1)"><i class="fa fa-edit"></i>&nbsp;同意</a><br/>' +
                                    '<a href="javascript:uptateItem(' + data + ',2)"><i class="fa fa-edit"></i>&nbsp;拒绝</a><br/>';
                        }
                        html+='<a href="javascript:deleteItem(' +data + ')"><i class="fa fa-trash-o"></i>&nbsp;删除</a>';
                        return html

                    }
                }
             ],
            "language": lang
        });
    });

    function uptateItem(id,status) {
        var title = status == 1 ? '确定同意吗?' : '确定拒绝吗?';
        $.messager.confirm('提示信息', title, function (result) {
            if (!result) return false;
            $.post('{:U("Feedback/agent")}', "id=" + id+"&result="+status, function (res) {
                if (!res.status) {
                    $.messager.alert('提示信息', res.info, 'error');
                } else {
                    feedbackTable.fnDraw(false);
                }
            }, 'json');
        });
    }


    function shareItem(id) {
        $.messager.confirm('提示信息', '确定共享此信息吗?', function (result) {
            if (!result) return false;
            $.dialog("{:U('Feedback/shareInfo')}?id="+id, '共享路况');
        });
    }

    function deleteItem(id) {
        $.messager.confirm('提示信息', '确定删除此信息吗?', function (result) {
            if (!result) return false;
            $.post('{:U("Feedback/deleteItem")}', "id=" + id, function (res) {
                if (!res.status) {
                    $.messager.alert('提示信息', res.info, 'error');
                } else {
                    feedbackTable.fnDraw(false);
                }
            }, 'json');
        });
    }

</script>